package com.sc.nft.controller;

import com.sc.nft.annotation.UserLogin;
import com.sc.nft.controller.request.IdRequest;
import com.sc.nft.entity.dto.CurrentAffairsTypeDTO;
import com.sc.nft.entity.vo.CurrentAffairsDetailVo;
import com.sc.nft.entity.vo.CurrentAffairsDetailsVO;
import com.sc.nft.entity.vo.CurrentAffairsTypeVo;
import com.sc.nft.entity.vo.NoticeInfoVO;
import com.sc.nft.service.CurrentAffairsService;
import com.sc.nft.service.CurrentAffairsTypeService;
import com.sc.nft.service.NoticeInfoService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 时政要闻表服务控制器
 *
 * @author zhangchao
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2024-03-05 10:52:52
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/currentAffairs")
@Api(tags = "资讯管理")
public class CurrentAffairsController {
    private final CurrentAffairsService currentAffairsService;
    private final NoticeInfoService noticeInfoService;
    private final CurrentAffairsTypeService currentAffairsTypeService;


    @ApiOperation(value = "获取资讯列表", notes = "获取资讯列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getCurrentAffairsRecommend", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<List<CurrentAffairsDetailsVO>> getCurrentAffairsRecommend(@Valid @RequestBody CurrentAffairsTypeDTO currentAffairsTypeDTO) {
        return PageResult.success(currentAffairsService.getCurrentAffairsRecommendPage(currentAffairsTypeDTO));
    }

    @ApiOperation(value = "获取类型模块名称", notes = "获取类型模块名称", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getCurrentAffairsTypeVo", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<List<CurrentAffairsTypeVo>> getCurrentAffairsTypeVo() {
        return Result.success(currentAffairsTypeService.getCurrentAffairsTypeVoIsOpen());
    }

    @ApiOperation(value = "资讯详情", notes = "资讯详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/currentAffairsDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<CurrentAffairsDetailVo> currentAffairsDetails(@Valid @RequestBody IdRequest idRequest) {
        return Result.success(currentAffairsService.currentAffairsDetails(idRequest.getId()));
    }

    @ApiOperation(value = "获取公告栏最近三条消息", notes = "获取公告栏最近三条消息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/listNotice", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<List<NoticeInfoVO>> listNotice() {
        return Result.success(noticeInfoService.listNotice());
    }

}


